#use Test::More tests 1;
use Test::More 'no_plan';
use JSON ();
use Data::Dumper;
use Dancer ();
use strict;
#use encoding 'utf-8';
use Encode;

use e4e;
use Dancer::Test;
use e4eTest;

#设置log输出和级别
Dancer::set logger => 'file';
Dancer::set log => 'core';

my $is_int = re('^-?\d+$');
my $is_str = re('^\w+$');

my $total=0;
#测试链路
route_exists [POST => '/admin'], '/admin链路正常';
++$total;

#根据id设置学期
deeply_req 'admin', 'set_term',
{
	term_id => 1,
	term_name => '设置学期',
},
{
	term_id => 1,
	term_name => '设置学期',
};

#拉取该学期
deeply_req 'admin', 'get_term',
{
	term_id => [ 1 ],
},
{
	term => [
		{
			term_id => 1,
			term_name => '设置学期',
		},
	],
};

#新增学期
deeply_req 'admin', 'set_term',
{
	term_name => 'new_term',
},
{
	term_id => $is_int,
	term_name => 'new_term',
};

#拉取所有学期
deeply_req 'admin', 'get_term',
{
	term_id => [],
},
{
	term => array_each(
		{
			term_id => $is_int,
			term_name => $is_str,
		},
	),
};

#设置班级
deeply_req 'admin', 'set_class',
{
	term_id => 1,
	class_id => 1,
	class_name => 'update_class',
},
{
	term_id => 1,
	class_id => 1,
	class_name => 'update_class',
};

#拉取指定id班级
deeply_req 'admin', 'get_class',
{
	term_id => 1,
	class_id => [ 1 ],
},
{
	class => [
		{
			class_id => 1,
			term_id => 1,
			class_name => 'update_class',
		}
	],
};

#增加班级
deeply_req 'admin', 'set_class',
{
	term_id => 1,
	class_name => 'new_class',
},
{
	term_id => 1,
	class_id => $is_int,
	class_name => 'new_class',
};

#拉取所有班级
deeply_req 'admin', 'get_class',
{
	term_id => 1,
	class_id => [],
},
{
	class => array_each(
		{
			class_id => $is_int,
			term_id => $is_int,
			class_name => $is_str,
		},
	),
};

#设置指定id小组
deeply_req 'admin', 'set_group',
{
	group_id => 1,
	term_id => 1,
	class_id => 1,
	group_name => 'update_group',
},
{
	group_id => 1,
	term_id => 1,
	class_id => 1,
	group_name => 'update_group',
};

deeply_req 'admin', 'get_group',
{
	term_id => 1,
	class_id => 1,
	group_id => [ 1 ],
},
{
	group => [
		{
			group_id => 1,
			term_id => 1,
			class_id => 1,
			group_name => 'update_group',
		},
	],
};

#增加评价数据
deeply_req 'admin', 'add_evaluation',
{
	score => [
		{
			term_id => 1,
			class_id => 1,
			group_id => 0,
			student_id => 0,
			lesson => 'match',
			score_type => 0,
			score => 100,
		},
	],
},
{
	total => 1,
};

deeply_req 'admin', 'get_evaluation',
{
	term_id => 1,
	class_id => 1,
},
{
	score => array_each (
		{
			term_id => $is_int,
			class_id => $is_int,
			group_id => $is_int,
			student_id => $is_int,
			lesson => $is_str,
			score_type => $is_int,
			score => $is_int,
		}
	),
};

deeply_req 'admin', 'get_student',
{
	term_id => 1,
	class_id => 1,
	group_id => 1,
},
{
	student => array_each (
		{
			student_id => $is_int,
			term_id => $is_int,
			class_id => $is_int,
			group_id => $is_int,
			student_name => $is_str,
		}
	),
};

deeply_req 'admin', 'get_scoretype',
{
	term_id => 1,
},
{
	score_type => array_each (
		{
			score_id => $is_int,
			term_id => $is_int,
			score_name => $is_str,
		}
	),
};
